Reading Encoded Data
MVOM allows for the reading of data from a DIR-type file as a base-64 encoded string. The static readFileContentsById
method of the Model
class can be used for this functionality.
info
The file name used to create the Model
class must have a record in the VOC file pointing to the location on disk where the directory resides.
readFileContentsById
The readFileContentsById
method allows for reading a file from a directory and returning a Base-64 Encoded representation of the file's contents.
Syntax
static readFileContentsById(id: string, options?: ModelReadFileContentsByIdOptions): Promise<string>
Parameters
Parameter | Type | Description |
---|---|---|
id | string | The record ID of the record to read |
options | object | Options object (see below) |
Options Object Properties
Property | Type | Description |
---|---|---|
maxReturnPayloadSize | number | The maximum allowed return payload size in bytes. If this size is exceeded a DbServerError will be thrown. If omitted the value specified during connection creation is used. |
requestId | string | A request/trace ID to be passed to MVIS as a request header with the key X-MVIS-Trace-Id |
userDefined | object | The user defined options to pass to the database subroutines |
Example
const Encoded = connection.model(null, 'SOME_DIRECTORY');
const encoded = await Encoded.readFileContentsById('SOME_FILE');
How It Works
The general workflow of this method is as follows:
- Read the
VOC
record for the file which was used to create theModel
- Take the path to the file from attribute 2 of the
VOC
record - Append a
/
and the id specified to the path - Read and encode the contents of the file by passing the full path to the MultiValue Basic
encode
function.